package com.lu.test;

import com.alibaba.fastjson.JSON;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * @author luke
 * @date 2021/09/16 11:38
 */
public class ObjectStream {
    static String[] ss = new String[]{"1","中国"};

    public static void main(String[] args) throws Exception{
        writeO();

    }

    public static void writeO() throws Exception{
        System.out.println(Charset.defaultCharset());
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(bao);
        o.writeObject(ss);
        byte[] byteArray = bao.toByteArray();
        bao.close();
        o.close();

        FileOutputStream f = new FileOutputStream("C:\\Users\\issuser\\Desktop\\Array.txt");
        f.write(byteArray);
        f.close();
    }

    public static void writeF() throws Exception{
            FileOutputStream f = new FileOutputStream("C:\\Users\\issuser\\Desktop\\Array1.txt");
            ObjectOutputStream o = new ObjectOutputStream(f);
            o.writeObject(ss);
            f.close();
            o.close();
    }

    public static void writeC() throws Exception{
        FileOutputStream f = new FileOutputStream("C:\\Users\\issuser\\Desktop\\Array2.txt");
        OutputStreamWriter wr = new OutputStreamWriter(f, StandardCharsets.UTF_8);
        wr.write(ss[0]);
        wr.write(ss[1]);
        wr.close();
        f.close();
    }

    public static void writeS() throws Exception{

        FileWriter fw = new FileWriter("C:\\Users\\issuser\\Desktop\\Array3.txt");
        fw.write("中文汉字");
        System.out.println(fw.getEncoding());
        fw.close();

    }

}
